package com.a51integrated.sfs2x;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;

import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.variables.*;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;

public class ValidateWinConditionRequestHandler extends BaseClientRequestHandler {

	@Override
	public void handleClientRequest(User player, ISFSObject params) {
		// TODO Auto-generated method stub

		// Obtain the user's score that is stored server-side, and return this in a response to the user.
		UserVariable userScoreVariable = player.getVariable("score");
		
		boolean WinConditionMet = userScoreVariable.getIntValue() > 3000;	// 3000 is the score limit.

		trace("User " + player.getName() + " request win condition validation. Result: " + ((WinConditionMet)?("true"):("false")) );
				
		// Store the score in a return object.
		ISFSObject rtn = new SFSObject();
		rtn.putBool("winConditionMet", WinConditionMet );
		
		// Construct the message to send.
		GameExtension parentEx = (GameExtension) getParentExtension();
		parentEx.send("validatewincondition", rtn, player);	
	}

}
